using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics.Contracts;
using Konst3d.Efficiency.Suite;

namespace Konst3d.Efficiency.Suite.SparsedBinary
{
    internal interface IBuyStorage
    {
        void UpdateBuyState        (int id, BuyState state);
        void UpdateBuyTitle        (int id, string title);
        void UpdateBuyDescription  (int id, string description);
        void UpdateBuySeverity     (int id, int severity);
        void UpdateBuyPrice        (int id, double price);
        void UpdateBuyDeadLine     (int id, DateTime deadLine);
        void UpdateBuyCreated      (int id, DateTime created);
    }

    internal class Buy: IBuy
    {
        #region Constructor

        public Buy(IBuyStorage storage, int id, BuyState state, string title, string description, int severity, double price, DateTime deadLine, DateTime created)
        {
            Contract.Assert(storage != null);

            _storage = storage;
            _id = id;
            _state = state;
            _title = title;
            _description = description;
            _severity = severity;
            _price = price;
            _deadLine = deadLine;
            _created = created;
        }

        #endregion // Constructor

        #region IBuy Members

        public BuyState State
        {
            get
            {
                return _state;
            }
            set
            {
                _storage.UpdateBuyState(_id, value);
                _state = value;
            }
        }

        public string Title
        {
            get
            {
                return _title;
            }
            set
            {
                _storage.UpdateBuyTitle(_id, value);
                _title = value;
            }
        }

        public string Description
        {
            get
            {
                return _description;
            }
            set
            {
                _storage.UpdateBuyDescription(_id, value);
                _description = value;
            }
        }

        public int Severity
        {
            get
            {
                return _severity;
            }
            set
            {
                _storage.UpdateBuySeverity(_id, value);
                _severity = value;
            }
        }

        public double Price
        {
            get
            {
                return _price;
            }
            set
            {
                _storage.UpdateBuyPrice(_id, value);
                _price = value;
            }
        }

        public DateTime DeadLine
        {
            get
            {
                return _deadLine;
            }
            set
            {
                _storage.UpdateBuyDeadLine(_id, value);
                _deadLine = value;
            }
        }

        public DateTime Created
        {
            get
            {
                return _created;
            }
            set
            {
                _storage.UpdateBuyCreated(_id, value);
                _created = value;
            }
        }

        #endregion

        #region IIdentifiable<int> Members

        public int ID
        {
            get
            {
                return _id;
            }
        }

        #endregion

        #region Overriden Methods

        public override bool Equals(object obj)
        {
            Buy other = obj as Buy;

            if (other != null)
            {
                return other.ID == _id;
            }

            return false;
        }

        #endregion // Overriden Methods

        #region Fields

        private IBuyStorage _storage;
        private int _id;
        private BuyState _state;
        private string _title;
        private string _description;
        private int _severity;
        private double _price;
        private DateTime _deadLine;
        private DateTime _created;

        #endregion // Fields
    }
}
